home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 1014 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.4 KB

  1. Path: easy.in-chemnitz.de!mkmk!floh
  2. From: floh@mkmk.in-chemnitz.de (Andre Weissflog)
  3. Newsgroups: comp.sys.amiga.programmer,uiuc.class.cs110c,uiuc.class.cs223
  4. Subject: Re: How do I define my integers?
  5. Message-ID: <D33Xx*bB0@mkmk.in-chemnitz.de>
  6. Date: Sun, 14 Jan 1996 02:52:23 CET
  7. Reply-To: floh@mkmk.in-chemnitz.de
  8. References: <4d73ug$25v@vixen.cso.uiuc.edu>
  9. Distribution: world
  10. Organization: private uucp site
  11. X-Newsreader: Arn V 1.04
  12.  
  13. In article <4d73ug$25v@vixen.cso.uiuc.edu>, howard daniel joseph writes:
  14.  
  15. >       Okay. I'm writing a program under GCC on my Amiga.
  16. >       But I'm confused to hell over integer limits.
  17. >       My book talks about 2 bit and 4 bit integers ... and four bit 
  18.                                         ^^^
  19.                                         should be bytes
  20.  
  21. > integers like what it describers long integers to be. Of course there's 
  22. > unsigned integers and the like too.
  23. The only rule about int types in C is IMHO that
  24.  
  25.     short <= int <= long
  26.  
  27. meaning that "short" can hold a smaller or equal number range
  28. then "int" and the same for "int" versus "long".
  29.  
  30. With most Amiga compilers, "short" holds 16 bit accuracy,
  31. "int" and "long" hold 32 bits. On the PC, older "16-bit compilers"
  32. have often 16 bit ints.
  33.  
  34. The best solution is to consistently use the types defined in 
  35. <exec/types.h>, called
  36.  
  37.     BYTE    - signed (8-bit) byte
  38.     UBYTE   - unsigned (8-bit) byte
  39.     WORD    - the same for 16 bit
  40.     UWORD
  41.     LONG    - the same for 32 bits
  42.     ULONG
  43.  
  44. > How do I declare signed versus unsigned integers?
  45.  
  46. With "raw ANSI"
  47.  
  48.     int a;  - gives a signed variable (16 or 32 bits! compiler-dependent)
  49.     unsigned int a;     - the same for unsigned
  50.  
  51. With Amiga conventions:
  52.  
  53.     ULONG a;    - gives an unsigned 32 bit integer
  54.     LONG a;     - the same signed
  55.  
  56. > How do I know how many bits my integers are using?
  57. see above :-)
  58.  
  59. > How do I declare signed and unsigned long integers?
  60. see above
  61.  
  62. > What's with these "doubles" the book mysteriously alludes to?
  63. Floating point numbers. Only useful for number crunching IMHO.
  64.  
  65. > What *am* I creating when I type;
  66. > int somevalue;
  67. > (ie Is it signed/unsigned? How many bits?)
  68. This is signed, it depends on your compiler, if it is 16 or 32 bits,
  69. usually it is 32 bits.
  70.  
  71. > I know many of the answers here, but if I could get them all from one 
  72. > source I'd feel a lot better.
  73. > I need two sorts of values for my project;
  74. > An integer (unsigned) that can handle, 6, though ideally 9 places (Just 
  75. > under 250000000 would be the maximum forseen possible value here.)
  76. 250,000,000 decimal would fit into an signed 32 bit integer
  77. (a "int" or a "long" in ANSI, or a "LONG" with Amiga conventions).
  78.  
  79. > An integer that can handle a much bigger number ... 12 places at least for 
  80. > now.
  81. Aargh, no chance with 32 bit numbers. (2^32)-1 is 4,294,967,295,
  82. so no luck for you. Why in the world do you need such big numbers???
  83.  
  84. > Can I perform simple maths (addition, division) between integers of 
  85. > different types? I'd assume so, right?
  86. Yes, the compiler will do what it can to ensure results that
  87. make sense. Be careful with unsigned numbers (they can't get
  88. smaller then 0).
  89.  
  90. Bye,
  91. -Floh.
  92.  
  93. ====//=== Andre Weissflog <floh@mkmk.in-chemnitz.de> =======
  94. ...// Sep'95: Return Of The Living Death...................
  95. \\// 90% of everything is crap (Sturgeon's Law)...........
  96. =\\===============================================Amiga!=
  97.  
  98.